/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedBean.TX.SABM;

import entity.AdvertisementStatistics;
import entity.Stakeholder;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import managedBean.TX.CustomerIOTRPortal.FakeMainPortalMB;
import managedBean.TX.OutletManagement.PhotoMB;
import session.TX.AdvertisementSBRemote;

/**
 *
 * @author AdminNUS
 */
@ManagedBean(name = "advertisementMB")
public class AdvertisementMB {

    @EJB
    private AdvertisementSBRemote adsBean;

    @ManagedProperty(value = "#{photoManagedBean}")
    private PhotoMB photoMB;
    private String tags;
    private String filePath = "";
    private String description;
    private String link;
    private boolean isSubscription;
    private boolean isImpression;
    private Double biddingPrice;
    private boolean isActivated;
    private Integer maxClicks;
    private Integer maxImpression;
    private Stakeholder stakeholder;
    private List<AdvertisementStatistics> AdvertisementStatistics;
    private Date startDate;
    private Date endDate;
    private String statusMessage;


    /**
     * @return the filePath
     */
    public String getFilePath() {
        return filePath;
    }

    /**
     * @param filePath the filePath to set
     */
    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }

    /**
     * @return the description
     */
    public String getDescription() {
        return description;
    }

    /**
     * @param description the description to set
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @return the link
     */
    public String getLink() {
        return link;
    }

    /**
     * @param link the link to set
     */
    public void setLink(String link) {
        this.link = link;
    }

    /**
     * @return the isSubscription
     */
    public boolean isIsSubscription() {
        return isSubscription;
    }

    /**
     * @param isSubscription the isSubscription to set
     */
    public void setIsSubscription(boolean isSubscription) {
        this.isSubscription = isSubscription;
    }

    /**
     * @return the isImpression
     */
    public boolean isIsImpression() {
        return isImpression;
    }

    /**
     * @param isImpression the isImpression to set
     */
    public void setIsImpression(boolean isImpression) {
        this.isImpression = isImpression;
    }

    /**
     * @return the biddingPrice
     */
    public Double getBiddingPrice() {
        return biddingPrice;
    }

    /**
     * @param biddingPrice the biddingPrice to set
     */
    public void setBiddingPrice(Double biddingPrice) {
        this.biddingPrice = biddingPrice;
    }

    /**
     * @return the isActivated
     */
    public boolean isIsActivated() {
        return isActivated;
    }

    /**
     * @param isActivated the isActivated to set
     */
    public void setIsActivated(boolean isActivated) {
        this.isActivated = isActivated;
    }

    /**
     * @return the maxClicks
     */
    public Integer getMaxClicks() {
        return maxClicks;
    }

    /**
     * @param maxClicks the maxClicks to set
     */
    public void setMaxClicks(Integer maxClicks) {
        this.maxClicks = maxClicks;
    }

    /**
     * @return the maxImpression
     */
    public Integer getMaxImpression() {
        return maxImpression;
    }

    /**
     * @param maxImpression the maxImpression to set
     */
    public void setMaxImpression(Integer maxImpression) {
        this.maxImpression = maxImpression;
    }

    /**
     * @return the stakeholder
     */
    public Stakeholder getStakeholder() {
        return stakeholder;
    }

    /**
     * @param stakeholder the stakeholder to set
     */
    public void setStakeholder(Stakeholder stakeholder) {
        this.stakeholder = stakeholder;
    }

    /**
     * @return the AdvertisementStatistics
     */
    public List<AdvertisementStatistics> getAdvertisementStatistics() {
        return AdvertisementStatistics;
    }

    /**
     * @param AdvertisementStatistics the AdvertisementStatistics to set
     */
    public void setAdvertisementStatistics(List<AdvertisementStatistics> AdvertisementStatistics) {
        this.AdvertisementStatistics = AdvertisementStatistics;
    }

    /**
     * @return the tags
     */
    public String getTags() {
        return tags;
    }

    /**
     * @param tags the tags to set
     */
    public void setTags(String tags) {
        this.tags = tags;
    }

    public void addNewAdvertisement(ActionEvent event) {


        boolean status = adsBean.addAdvertisement(tags,
                photoMB.getDishFilePath(),
                description,
                link,
                isSubscription,
                isImpression,
                biddingPrice,
                isActivated,
                maxClicks,
                maxImpression, FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("stakeholderName").toString(), startDate, endDate);
        
        if(status=true)
        {
            setStatusMessage("Advertisement created successfully");
            FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Result: " + getStatusMessage(), ""));
        }
        else{
             setStatusMessage("Advertisement not created");
              FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Result: " + getStatusMessage(), ""));
    }
    }

    /**
     * @return the startDate
     */
    public Date getStartDate() {
        return startDate;
    }

    /**
     * @param startDate the startDate to set
     */
    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    /**
     * @return the endDate
     */
    public Date getEndDate() {
        return endDate;
    }

    /**
     * @param endDate the endDate to set
     */
    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    /**
     * @return the statusMessage
     */
    public String getStatusMessage() {
        return statusMessage;
    }

    /**
     * @param statusMessage the statusMessage to set
     */
    public void setStatusMessage(String statusMessage) {
        this.statusMessage = statusMessage;
    }
    /**
     * @return the photoMB
     */
    public PhotoMB getPhotoMB() {
    return photoMB;
    }
    
    /**
     * @param photoMB the photoMB to set
     */
     public void setPhotoMB(PhotoMB photoMB) {
    this.photoMB = photoMB;
    }
}
